﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>登入</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="layuiAdmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="layuiAdmin/style/admin.css" media="all">
    <link rel="stylesheet" href="layuiAdmin/style/login1.css?=1" media="all">

</head>

<body style="overflow: hidden;">
    <span class="login-warp"></span>
    <div class="login-wrapper layui-anim layui-anim-scale layui-hide"
        style="overflow: hidden; border: 1px solid #FCFEFE; border-radius: 3px;">
        <div class="layui-form">
            <h2>.Net后台 layuiAdmin版</h2>
            <div class="layui-form-item layui-input-icon-group">
                <i class="layui-icon layui-icon-username"></i>
                <input class="layui-input" name="username" value="xin" placeholder="请输入登录账号" autocomplete="off"
                    lay-verType="tips" lay-verify="required" required />
            </div>
            <div class="layui-form-item layui-input-icon-group">
                <i class="layui-icon layui-icon-password"></i>
                <input class="layui-input" name="password" value="" placeholder="请输入登录密码" type="password"
                    lay-verType="tips" lay-verify="required" required />
            </div>
            <div class="layui-form-item">
                <input type="checkbox" name="remember" title="记住密码" lay-skin="primary">
                <!--<a href="reg.html" class="layui-link pull-right">注册账号</a>-->
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" id="login" lay-filter="loginSubmit" lay-submit>登录</button>
            </div>
        </div>
        <span class="login-right-warp-one"></span>
        <span class="login-right-warp-two"></span>
    </div>
    <div class="login-copyright">copyright © 2022~2032 xin-life.cn all rights reserved.</div>
    <script src="layuiAdmin/modules/crypto-js.min.js"></script>
    <script>
        document.write("<script type='text/javascript' src='layuiAdmin/xin.js?v=" + Date.now() + "'><\/script>");
    </script>
    <script src="layuiAdmin/layui/layui.js"></script>
    <script>
        document.addEventListener('keydown', function (event) {
            if (event.key === 'Enter') {
                event.preventDefault();
                document.getElementById('login').click();
            }
        });

        layui.config({
            base: 'layuiAdmin/', //静态资源所在路径
            version: myLop.version
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'user'], function () {
            var $ = layui.$,
                setter = layui.setter,
                admin = layui.admin,
                form = layui.form,
                router = layui.router(),
                search = router.search;
            $('.login-wrapper').removeClass('layui-hide');
            form.render();
            if (layui.data(setter.tableName).LOGIN) {
                $('input[name="remember"]').attr("checked", true);
                form.render();
                $('input[name="username"]').val(layui.data(setter.tableName).LOGIN.username);
                $('input[name="password"]').val(layui.data(setter.tableName).LOGIN.password);
            }
            //提交
            form.on('submit(loginSubmit)', function (obj) {
                obj.field.password = CryptoJS.MD5(obj.field.password).toString();
                //请求登入接口
                admin.req({
                    type: 'post',
                    url: '/api/Login/Login',
                    data: obj.field,
                    success: function (res) {
                        if (res.code == 200) {
                            layui.sessionData(setter.tableName, {
                                key: setter.request.tokenName,
                                value: res.data.auth_token.token_type + ' ' + res.data.auth_token.token
                            });
                            layui.sessionData(setter.tableName, {
                                key: 'UserInfo',
                                value: res.data
                            });
                            if (obj.field.remember) {
                                layui.data(setter.tableName, {
                                    key: 'LOGIN',
                                    value: {
                                        'username': obj.field.username,
                                        'password': obj.field.password
                                    }
                                })
                            } else {
                                layui.data(setter.tableName, {
                                    key: 'LOGIN',
                                    remove: true
                                });
                            }
                            //登入成功的提示与跳转
                            layer.msg('登入成功', {
                                offset: '15px',
                                icon: 1,
                                time: 1000
                            }, function () {
                                location.href = 'index.html'; //后台主页
                            });
                        } else {
                            layer.msg(res.msg)
                        }
                    }
                });

            });

        });
    </script>
</body>

</html>